﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Microsoft.SharePoint;

namespace JobUsersSync3Test
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void testToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Exception err = null;

            JobUsersSync3.Features.JobUsersSync3.JobUsersSync3 o =
                new JobUsersSync3.Features.JobUsersSync3.JobUsersSync3();

            Dictionary<DateTime, string> InfDict = new Dictionary<DateTime,string>();
            err = o.GetUsersLists(ref InfDict);
            ToLog(ref InfDict, ref err);

            //o.SPList_BirthdaysAll_DeleteAll();

            InfDict = new Dictionary<DateTime, string>();
            err = o.VerifyOfficeUsers(InfDict);
            err = o.VerifyNotOfficeUsers(InfDict);
        }

        private void test2ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            Exception err = null;

            Ko2.Sys.AD ad = new Ko2.Sys.AD();
            DataTable adUsersNotOfficeTbl = null;

            ad.MakeTableUserExtProp(ref adUsersNotOfficeTbl);
            err = ad.GetUsersInNotOffice(ref adUsersNotOfficeTbl, "Румянцево", true, true);

            gv.DataSource = adUsersNotOfficeTbl;
            
        }

        void ToLog(string parMsg)
        {
            DateTime dt = DateTime.Now;
            string dtStr = dt.ToShortDateString() + " ; " + dt.ToShortTimeString();
            ListViewItem item = oLog.Items.Insert(0, dtStr);
            item.SubItems.Add(parMsg);
            if(oLog.Items.Count>1)
            {
                oLog.Items[oLog.Items.Count - 1].Focused = false;
                //oLog.Items[oLog.Items.Count - 1].Selected = false;
            }
            item.Focused = true;
            //item.Selected = true;
        }

        void ToLog(ref Dictionary<DateTime, string> parDict, ref Exception err)
        {
            int iAll = parDict.Count;

            for(int i=0; i<iAll; i++)
            {
                DateTime dt = (DateTime)parDict.Keys.ElementAt(i);
                string msgStr = dt.ToShortDateString() + " ; " + dt.ToShortTimeString();
                ListViewItem item = oLog.Items.Insert(0, msgStr);
                item.SubItems.Add((string)parDict.Values.ElementAt(i));
                item.Focused = true;
                item.Selected = true;
                if (oLog.Items.Count >= 1)
                {
                    //oLog.Items[oLog.Items.Count - 1].Focused = false;
                    oLog.Items[oLog.Items.Count - 1].Selected = false;
                }
            }
            
            if (err != null)
            {
                DateTime dt = DateTime.Now;
                string msgStr = dt.ToShortDateString() + " ; " + dt.ToShortTimeString();
                ListViewItem item = oLog.Items.Insert(0, msgStr);
                item.SubItems.Add(err.Message);
                item.Focused = true;
                item.Selected = true;
                if (oLog.Items.Count >= 1)
                {
                    //oLog.Items[oLog.Items.Count - 1].Focused = false;
                    oLog.Items[oLog.Items.Count - 1].Selected = false;
                }
            }

        }

    }
}
